const dictStore = useDictStore();

/**
 * 获取字典数据
 */
export function useDict(...args: string[]) {
  const res = ref<DictMapRecord>({});
  args.forEach((dictType: string) => {
    res.value[dictType] = [];
    const dicts = dictStore.getDict(dictType);
    if (dicts) {
      res.value[dictType] = dicts;
    } else {
      getDictsApi(dictType).then(resp => {
        res.value[dictType] = resp.data.map(p => ({
          ...p,
          label: p.dictLabel,
          value: p.dictValue,
          elTagType: p.listClass,
        }))
        dictStore.setDict(dictType, res.value[dictType]);
      })
    }
  })
  return toRefs(res.value);
}